package com.linjiang.design.factory;

//抽象工厂模式（专注于一组有关联的产品的创建）
//提供一个创建一系列相关或相互依赖对象的接口，而无需指定它们具体的类
public class AbstractFactoryTest {
    public static void main(String[] args) {
        IDBComponent idbComponent = new OracleComponent();
        IConnection connection = idbComponent.getConnection();
        connection.connection();
        ICommand command = idbComponent.getCommand();
        command.command();
    }
}

interface IConnection{
    void connection();
}

interface ICommand{
    void command();
}

interface IDBComponent{
    IConnection getConnection();
    ICommand getCommand();

}

class MysqlConnection implements IConnection {

    @Override
    public void connection() {
        System.out.println("连接mysql");
    }
}

class OracleConnection implements IConnection {

    @Override
    public void connection() {
        System.out.println("连接Oracle");
    }
}

class MysqlCommand implements ICommand{

    @Override
    public void command() {
        System.out.println("发送mysql指令");
    }
}

class OracleCommand implements ICommand{
    @Override
    public void command() {
        System.out.println("发送oracle指令");
    }
}

class MysqlComponent implements IDBComponent{

    @Override
    public IConnection getConnection() {
        return new MysqlConnection();
    }

    @Override
    public ICommand getCommand() {
        return new MysqlCommand();
    }
}

class OracleComponent implements IDBComponent{

    @Override
    public IConnection getConnection() {
        return new OracleConnection();
    }

    @Override
    public ICommand getCommand() {
        return new OracleCommand();
    }
}